// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import BannerAd from "./BannerAd";

const { ccclass, property } = cc._decorator;

@ccclass
export default class YinSi extends cc.Component {

    isLoad = false;
    isTime = false;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        BannerAd.Instance.GetcityIswhite();
        if (localStorage.getItem("YinSi") == "1") this.Accept();
    }

    // update (dt) {}

    Accept() {
        localStorage.setItem("YinSi", "1");
        this.node.active = false;
        cc.assetManager.loadBundle("Sprite", () => {
            cc.assetManager.loadBundle("Sprite2", () => {
                this.isLoad = true;
                this.Ready();
            });
        });
        this.scheduleOnce(() => {
            this.isTime = true;
            this.Ready();
        }, 2);
    }

    Refuse() {
        BannerAd.Instance.Quit();
    }

    Ready() {
        if (this.isLoad && this.isTime) cc.director.loadScene("MainScene");
    }
}
